package org.centny.bb;

import java.util.Random;

public class Builder implements Gaming {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		BaccaratBuilder bb = new BaccaratBuilder();
		bb.setCardsCount(8);
		bb.shuffle();
		Builder b = new Builder();
		bb.follow(b);
		Random rd = new Random();
		for (int i = 0; i < 100000; i++) {
			b.follow_m = 100;
			b.followed = rd.nextInt(4) + 1;
			bb.gaming();
			if (b.money <= 0) {
				break;
			}
		}
		b.showRes();
	}

	public static final float WIN_RATE = 1;
	public static final float TIE_RATE = 8;
	public static final float PAIR_RATE = 11;
	//
	float maxMoney = 0;
	float money = 10000;
	public float follow_m = 0;
	public int followed = 0;
	//
	float pairCount = 0;
	float tieCount = 0;
	float playCount = 0;
	float bandCount = 0;
	float total = 0;

	@Override
	public void gaming(GRes res) {
		this.money -= this.follow_m;
		this.total++;
		if (res.paired) {
			this.pairCount++;
			if (this.followed == 4) {
				this.money += this.follow_m * (PAIR_RATE + 1);
			}
		}
		switch (res.g) {
		case GOPT_BANK:
			this.bandCount++;
			if (this.followed == 1) {
				this.money += this.follow_m * (WIN_RATE + 1);
			}
			break;
		case GOPT_PLAY:
			this.playCount++;
			if (this.followed == 2) {
				this.money += this.follow_m * (WIN_RATE + 1);
			}
			break;
		case GOPT_TIE:
			this.tieCount++;
			if (this.followed == 3) {
				this.money += this.follow_m * (WIN_RATE + 1);
			}
			break;
		}
		this.follow_m = 0;
		if (this.maxMoney < this.money) {
			this.maxMoney = this.money;
		}
	}

	public void showHelp() {
		System.out.println("Usage:<select> money");
		System.out.println("select:");
		System.out.println("\t 1 BANK");
		System.out.println("\t 2 PLAY");
		System.out.println("\t 3 TIE");
		System.out.println("\t 4 PAIR");
	}

	public void showRes() {
		System.out.println("Tie:" + (this.tieCount / this.total));
		System.out.println("Play:" + (this.playCount / this.total));
		System.out.println("Band:" + (this.bandCount / this.total));
		System.out.println("Pair:" + (this.pairCount / this.total));
		System.out.println("Total:" + this.total);
		System.out.println("MaxMoney:" + this.maxMoney);
		System.out.println("Money:" + this.money);
	}

}
